﻿<%@ WebHandler Language="C#" Class="EfficencyManage" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Hr;
using Chenxin.Lib.Hr.BLL;

public class EfficencyManage : AjaxHandlerBase
{
    /// <summary>
    /// 基本权限项
    /// </summary>
    public EfficencyManage()
    {
        //店长人数查询
        htTypePermit.Add("shoper", Constants.Permit_ShoperSearch);
        //业务员人数查询
        htTypePermit.Add("employee", Constants.Permit_EmployeeSearch);
        //人效计算
        htTypePermit.Add("calculate", Constants.Permit_EfficencyCalculate);
        //导出
        htTypePermit.Add("export", Constants.Permit_Efficency_Export);
        htTypePermit.Add("exportall", Constants.Permit_Efficency_Export);
    }
    
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        string strOp = context.Request["op"];
        string strResponse = "";
        switch (strOp.ToLower())
        {
            //查询
            case "search":
                strResponse = Search(context);
                break;
            //查看店长
            case "shoper":
                strResponse = SearchNum(context,"shoper");
                break;
            //查看业务员
            case "employee":
                strResponse = SearchNum(context, "employee");
                break;
            //人效计算
            case "calculate":
                strResponse = Calculate(context);
                break;
            case "exportall":
                ExportAll(context);
                break;
            default:
                break;
        }
        context.Response.Write(strResponse);
    }
    private static string EndDay = string.Empty;
    //*******************************************
    //功能概要       ：获得人效一览
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：获得人效一览
    //作成者         ：zou.xiaochun
    //作成日         ：2010-08-17
    //*******************************************
    private string Search(HttpContext context)
    {
        try
        {
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 50 : int.Parse(context.Request["pagesize"]);
            //查询条件
            string sqlWhere = GenerateCondition(context);

            //查询分页信息
            Chenxin.Lib.Hr.BLL.t_Efficency_Employee bllEfficency = new Chenxin.Lib.Hr.BLL.t_Efficency_Employee();
            string strYearMonth = string.Empty;
            strYearMonth = GetYearMonth(context);
            System.Data.DataSet ds = bllEfficency.GetModelListByCoditions(sqlWhere, strPageIndex, strPageSize, strYearMonth);
            //总页数
            int count = (int)ds.Tables[1].Rows[0][0];

            return string.Format("{{success:'1',msg:'{0}',data:{{count:'{1}',{2}}}}}", Resources.Message.Global_Msg_SUCCESS, count, JsonHelp.Convert2Json(ds.Tables[0]));
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }

    //*******************************************
    //功能概要       ：获得人效一览
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：获得人效一览
    //作成者         ：zou.xiaochun
    //作成日         ：2010-08-17
    //*******************************************
    private string SearchNum(HttpContext context,string status)
    {
        try
        {
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 50 : int.Parse(context.Request["pagesize"]);
            //查询条件
            StringBuilder sb = new StringBuilder();
            string strRecordid = context.Request["modelid"].ToString();
            sb.AppendFormat(" a.yearmonth=(select yearmonth from t_Efficency_Employee where recordid='{0}') and a.departid = (select departid from t_Efficency_Employee where recordid='{1}') and a.position='店长' ", strRecordid, strRecordid);
            string sqlWhere = sb.ToString();
            
            //查询分页信息
            Chenxin.Lib.Hr.BLL.t_Efficency_Employee bllEfficency = new Chenxin.Lib.Hr.BLL.t_Efficency_Employee();
            System.Data.DataSet ds = bllEfficency.GetModelByCoditions(sqlWhere, strPageIndex, strPageSize);

            string strCity = ds.Tables[0].Rows[0]["City"].ToString();
            string strCompany = ds.Tables[0].Rows[0]["Company"].ToString();
            string strBusinessdistrict = ds.Tables[0].Rows[0]["Businessdistrict"].ToString();
            string strDeparts = ds.Tables[0].Rows[0]["Departs"].ToString();
            string strYearMonth = ds.Tables[0].Rows[0]["YearMonth"].ToString();

            if (status == "employee")
            {
                ds = new DataSet();
                sb = new StringBuilder();
                sqlWhere = string.Empty;
                sb.AppendFormat(" City='{0}' and Company='{1}' and Businessdistrict='{2}' and Departs='{3}' and YearMonth='{4}' and Position='业务员'", strCity, strCompany, strBusinessdistrict, strDeparts, strYearMonth);
                sqlWhere = sb.ToString();
                //查询分页信息
                bllEfficency = new Chenxin.Lib.Hr.BLL.t_Efficency_Employee();
                ds = bllEfficency.GetEmpList(sqlWhere, strPageIndex, strPageSize);
            }
                
            //总页数
            int count = (int)ds.Tables[1].Rows[0][0];

            return string.Format("{{success:'1',msg:'{0}',data:{{count:'{1}',{2}}}}}", Resources.Message.Global_Msg_SUCCESS, count, JsonHelp.Convert2Json(ds.Tables[0]));
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }
    
    //*******************************************
    //功能概要       ：查询权限
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：生成查询条件语句
    //作成者         ：chen.yugong
    //作成日         ：2010-06-29
    //修改者         ：王玮
    //修改日         ：2010-07-13
    //*******************************************
    public string GenerateCondition(HttpContext context)
    {
        try
        {
            //获取页面查询条件
            Guid city = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty : new Guid(context.Request["cityid"]);
            Guid company = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty : new Guid(context.Request["companyid"]);
            Guid businessdistrict = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty : new Guid(context.Request["areaid"]);
            Guid departs = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty : new Guid(context.Request["departid"]);
            Guid employee = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty : new Guid(context.Request["userid"]);
            string yearmonth = string.Empty;
            string strCode = context.Request["EmployeeCode"];
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            yearmonth = GetYearMonth(context);
            
            //判断级联菜单
            if (employee != Guid.Empty)
                sb.AppendFormat(" and (a.EmployeeID = '{0}') ", employee);
            else if (departs != Guid.Empty)
                sb.AppendFormat(" and (a.DepartID = '{0}')", departs);
            else if (businessdistrict != Guid.Empty)
            {
                Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item = null;
                string strCachkey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_DEPARTMENT, businessdistrict);
                Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
                item = cs.GetObject<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>(strCachkey);
                if (!cs.Hit)
                {
                    item = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(businessdistrict);
                    if (item != null) cs.Set(strCachkey, item, DateTime.Now.AddDays(1));
                }

                if (item == null) return string.Format("{{success:'0',msg:'{0}',data:''}}", Resources.Message.Global_Err_GetBusDis);

                sb.AppendFormat(" and (a.DepartID in (select departId from Chenxin_Business.dbo.v_Hr_DepartmentInfo where DepartSrc like '{0}%'))", item.DepartSrc);
            }
            else if (company != Guid.Empty)
            {
                sb.AppendFormat(" and CompanyID = '{0}'", company);
            }
            else if (city != Guid.Empty)
            {
                sb.AppendFormat(" and CityID = '{0}'", city);
            }
            else
            {
                sb.AppendFormat(" and CompanyID = '{0}'", CurrentUserInfo.CompanyId);
            }

            //查询权限判断权限
            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            if (CurrentUserInfo.ContainsPermit(Constants.Permit_EfficencySearch_All))
            {
                sb1.Append(" (1=1) ");
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_EfficencySearch_City))
            {
                sb1.AppendFormat(" (CityID = '{0}')", CurrentUserInfo.CityId);
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_EfficencySearch_Company))
            {
                sb1.AppendFormat(" (CompanyID = '{0}')", CurrentUserInfo.CompanyId);
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_EfficencySearch_Depart))
            {
                sb1.Append(" (EXISTS(");
                sb1.AppendFormat("Select 1 from t_Business_EmpSetting M WHERE t_Efficency_Employee.DepartID=M.DepartId And M.Userid= '{0}'", CurrentUserInfo.UserId.ToString());
                sb1.Append(")) ");
            }
            else
            {
                sb1.AppendFormat(" (a.EmployeeID = '{0}')", CurrentUserInfo.UserId);
            }

            if (!String.IsNullOrEmpty(sb.ToString()))
            {
                sb1.Append(sb.ToString());
            }
            
            if (!String.IsNullOrEmpty(yearmonth))
            {
                sb1.AppendFormat(" and a.YearMonth = '{0}'", yearmonth);
            }
            sb1.Append(" and a.position in ('店长','区经','高经') and a.ishow=1 ");

            if (!string.IsNullOrEmpty(strCode))
            {
                sb1.AppendFormat(" and a.employeeId in (select userid from Hr_UserInfo where usercode like '%{0}%') ", strCode);
            }
            //sb1.Append(" group by a.RecordId,a.City,a.Company,a.Businessdistrict,a.Departs,a.Employee,a.Position,a.BeginTime,a.EndTime,a.ChangType,a.TransType,a.PeopleNum,a.YearMonth,b.PeopleNum ");
            return sb1.ToString();
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }

    public string GetYearMonth(HttpContext context)
    {
        string yearmonth = string.Empty;

        if (!string.IsNullOrEmpty(context.Request["year"]) && (!string.IsNullOrEmpty(context.Request["month"])))
        {
            yearmonth = context.Request["year"] + "." + context.Request["month"];
        }
        else
        {
            string year = System.DateTime.Now.Year.ToString();
            string month = string.Empty;
            if (System.DateTime.Now.Month.ToString().Length == 1)
            {
                month = "0" + (System.DateTime.Now.Month.ToString());
            }
            else if (System.DateTime.Now.Month.ToString().Length == 2)
            {
                month = (System.DateTime.Now.Month.ToString());
            }
            yearmonth = year + "." + month;
        }
        return yearmonth;
    }
    
    //*******************************************
    //功能概要       ：计算人效
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：计算人效
    //作成者         ：zou.xiaochun
    //作成日         ：2010-08-17
    //*******************************************
    private string Calculate(HttpContext context)
    {
        //计算人效信息
        string efficency = context.Request.Params["model"];

        //计算人效业务类
        Chenxin.Lib.Hr.BLL.t_Efficency_Employee bllEfficency = new Chenxin.Lib.Hr.BLL.t_Efficency_Employee();

        //计算人效
        Chenxin.Lib.Hr.Entity.t_Efficency_Employee entEfficency =
            (Chenxin.Lib.Hr.Entity.t_Efficency_Employee)JsonHelp.Convert2Entity(efficency,
                    typeof(Chenxin.Lib.Hr.Entity.t_Efficency_Employee));


        decimal DayNum = GetMonthDay(int.Parse(entEfficency.YearMonth.Substring(0, 4)), int.Parse(entEfficency.YearMonth.Substring(5, 2)));
        string BeginDay = entEfficency.YearMonth.Substring(0, 4) + "/" + entEfficency.YearMonth.Substring(5, 2) + "/01";

        //计算人效录入
        entEfficency.CityID = CurrentUserInfo.CityId;
        entEfficency.CompanyID = CurrentUserInfo.CompanyId;
        bllEfficency.Proce(entEfficency.CityID, entEfficency.CompanyID, entEfficency.YearMonth, BeginDay, EndDay, DayNum);
        bllEfficency.EProce(entEfficency.CityID, entEfficency.CompanyID, entEfficency.YearMonth, BeginDay, EndDay, DayNum);
        bllEfficency.HProce(entEfficency.CityID, entEfficency.CompanyID, entEfficency.YearMonth, BeginDay, EndDay, DayNum);
        return retExecResult(Constants.ExecResult.Succ, "计算成功！", "");
    }

    private decimal GetMonthDay(int year, int month)
    {
        decimal dayNum = 0;

        if (month == 2)
        {
            if (DateTime.IsLeapYear(year))
            {
                dayNum = 29;
                EndDay = year.ToString() + "/0" + month.ToString() + "/" + "29";
            }
            else
            {
                dayNum = 28;
                EndDay = year.ToString() + "/0" + month.ToString() + "/" + "28";
            }
        }
        else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        {
            dayNum = 31;
            if (month.ToString().Length == 2)
            {
                EndDay = year.ToString() + "/" + month.ToString() + "/" + "31";
            }
            else
            {
                EndDay = year.ToString() + "/0" + month.ToString() + "/" + "31";
            }
        }
        else
        {
            dayNum = 30;
            if (month.ToString().Length == 2)
            {
                EndDay = year.ToString() + "/" + month.ToString() + "/" + "30";
            }
            else
            {
                EndDay = year.ToString() + "/0" + month.ToString() + "/" + "30";
            }
        }

        return dayNum;
    }

    //导出全部的方法
    private void ExportAll(HttpContext context)
    {
        //获取页面查询条件
        Guid city = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty : new Guid(context.Request["cityid"]);
        Guid company = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty : new Guid(context.Request["companyid"]);
        Guid businessdistrict = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty : new Guid(context.Request["areaid"]);
        Guid departs = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty : new Guid(context.Request["departid"]);
        Guid employee = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty : new Guid(context.Request["userid"]);
        string yearmonth = string.Empty;
        string strCode = context.Request["EmployeeCode"];
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        yearmonth = GetYearMonth(context);

        //判断级联菜单
        if (employee != Guid.Empty)
            sb.AppendFormat(" and (a.EmployeeID = '{0}') ", employee);
        else if (departs != Guid.Empty)
            sb.AppendFormat(" and (a.DepartID = '{0}')", departs);
        else if (businessdistrict != Guid.Empty)
        {
            Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item = null;
            string strCachkey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_DEPARTMENT, businessdistrict);
            Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
            item = cs.GetObject<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>(strCachkey);
            if (!cs.Hit)
            {
                item = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(businessdistrict);
                if (item != null) cs.Set(strCachkey, item, DateTime.Now.AddDays(1));
            }

            //if (item == null) return string.Format("{{success:'0',msg:'{0}',data:''}}", Resources.Message.Global_Err_GetBusDis);

            sb.AppendFormat(" and (a.DepartID in (select departId from Chenxin_Business.dbo.v_Hr_DepartmentInfo where DepartSrc like '{0}%'))", item.DepartSrc);
        }
        else if (company != Guid.Empty)
        {
            sb.AppendFormat(" and CompanyID = '{0}'", company);
        }
        else if (city != Guid.Empty)
        {
            sb.AppendFormat(" and CityID = '{0}'", city);
        }
        else
        {
            sb.AppendFormat(" and CompanyID = '{0}'", CurrentUserInfo.CompanyId);
        }

        //查询权限判断权限
        System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
        if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_All))
        {
            sb1.Append(" (1=1) ");
        }
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_City))
        {
            sb1.AppendFormat(" (CityID = '{0}')", CurrentUserInfo.CityId);
        }
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_Company))
        {
            sb1.AppendFormat(" (CompanyID = '{0}')", CurrentUserInfo.CompanyId);
        }
        else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_Depart))
        {
            sb1.Append(" (EXISTS(");
            sb1.AppendFormat("Select 1 from t_Business_EmpSetting M WHERE t_Efficency_Employee.DepartID=M.DepartId And M.Userid= '{0}'", CurrentUserInfo.UserId.ToString());
            sb1.Append(")) ");
        }
        else
        {
            sb1.AppendFormat(" (a.EmployeeID = '{0}')", CurrentUserInfo.UserId);
        }

        if (!String.IsNullOrEmpty(sb.ToString()))
        {
            sb1.Append(sb.ToString());
        }

        if (!String.IsNullOrEmpty(yearmonth))
        {
            sb1.AppendFormat(" and a.YearMonth = '{0}'", yearmonth);
        }
        sb1.Append(" and a.position in ('店长','区经','高经') and a.ishow=1 ");

        if (!string.IsNullOrEmpty(strCode))
        {
            sb1.AppendFormat(" and a.employeeId in (select userid from Hr_UserInfo where usercode like '%{0}%') ", strCode);
        }


        //条件
        string strWhere = sb1.ToString();

        StringBuilder sbTableFieldList = new StringBuilder();
        sbTableFieldList.Append("a.RecordId,a.City,a.Company,a.Businessdistrict,a.Departs,(select UserCode from dbo.Hr_UserInfo WHERE UserId = a.EmployeeId) as EmployeeCode,a.Employee,a.Position,dateadd(dd,1,a.BeginTime) as BeginTime,dateadd(dd,0,a.EndTime) as EndTime," +
                                "a.ChangType,a.TransType,a.PeopleNum,a.YearMonth,cast((a.PeopleNum*b.PeopleNum)as decimal(5,2)) as TotalNum");

        //所要查询的表名
        StringBuilder TableName = new StringBuilder();
        TableName.AppendFormat(" (select RecordId,CityID,City,CompanyID,Company,BusinessdistrictID,Businessdistrict,DepartID,Departs,EmployeeID,Employee,PeopleNum,Position,BeginTime,EndTime,ChangType,TransType,YearMonth,ishow " +
                            "from t_Efficency_Employee where position in ('店长','区经','高经') and YearMonth = '{0}' " +
                            "group by RecordId,CityID,City,CompanyID,Company,BusinessdistrictID,Businessdistrict,DepartID,Departs,EmployeeID,Employee,PeopleNum,Position,BeginTime,EndTime,ChangType,TransType,YearMonth,ishow)a " +
                            "inner join (select c.DepartID,cast(sum(PeopleNum)as decimal(5,2)) as PeopleNum,c.YearMonth from " +
                            "(select DepartID,EmployeeID,PeopleNum,YearMonth from t_Efficency_Employee where isum = 1 and YearMonth = '{1}' " +
                            "group by DepartID,EmployeeID,PeopleNum,YearMonth)c group by c.DepartID,c.YearMonth)b on a.DepartID = b.DepartID ", yearmonth, yearmonth);
        //集计
        string GroupField = " a.RecordId,a.City,a.Company,a.Businessdistrict,a.Departs,a.EmployeeId,a.Employee,a.Position,a.BeginTime,a.EndTime,a.ChangType,a.TransType,a.PeopleNum,a.YearMonth,b.PeopleNum ";
        //排序
        string strOrderField = " Businessdistrict,Departs,Employee";

        string strSql = "select " + sbTableFieldList.ToString() + " from " + TableName + " where " + strWhere + " group by " + GroupField + " order by " + strOrderField;
        //根据sql执行查询
        DataSet ds = Chenxin.Lib.Hr.DAL.t_Efficency_Employee.GetExportList(strSql);
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            string strYearMonth = ds.Tables[0].Rows[i]["YearMonth"].ToString();
            ds.Tables[0].Rows[i]["YearMonth"] = strYearMonth.Substring(0, 4).ToString() + "年" + strYearMonth.Substring(5, 2).ToString() + "月";
        }
        string strHTML = GetHtml(ds.Tables[0]);

        ExportByServce(context, strHTML);
    }

    //导出全部的HTML
    private string GetHtml(DataTable dt)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<table class=\"tabsorternew table_archive\"><tr>");
        sb.Append("<th style=\"width:80px;\" >城市</th>");
        sb.Append("<th style=\"width:80px;\" >公司</th>");
        sb.Append("<th style=\"width:120px;\" >商圈</th>");
        sb.Append("<th style=\"width:130px;\" >门店</th>");
        sb.Append("<th style=\"width:100px;\" >工号</th>");
        sb.Append("<th style=\"width:80px;\" >店长</th>");
        sb.Append("<th style=\"width:80px;\" >店长人数</th>");
        sb.Append("<th style=\"width:80px;\" >店长总人数</th>");
        sb.Append("<th style=\"width:80px;\" >年月</th></tr>");

        foreach (System.Data.DataRow dr in dt.Rows)
        {
            sb.Append("<tr>");
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "City", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "Company", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "Businessdistrict", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "Departs", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "EmployeeCode", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "Employee", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "PeopleNum", ""));
            sb.AppendFormat("<td>{0}</td>", DatasetHelper.GetValue(dr, "TotalNum", ""));
            sb.AppendFormat("<td>{0}</td></tr>", DatasetHelper.GetValue(dr, "YearMonth", ""));
        }
        return sb.ToString();
    }
}